<? if ($c = stack('name')) {

	$d = component_data($c); 
	$s = component_settings($c);
	
	addScriptLink('jquery, jquery.tools');	

	if ($s['fancybox'])
		addScriptLink('jquery.fancybox.pack');

startScript(); ?><script type="text/javascript">jQuery(function($) {<?

	 switch($s['nav']) {
		 
		 case 0: // scrollable
		
?>	$("#cpn-<?=$c?> .scrollable").scrollable({
		mousewheel:true
		<?=$s['circular'] ? ', circular:true' : ''?>
	})<?=$s['navigator'] ? '.navigator()' : ''?><?=$s['autoscroll'] ? '.autoscroll(7000)' : ''?>;
<?
			break;
			
		case 1: // parallax
		
			addScriptLink('jquery.event.frame');
			addScriptLink('jquery.jparallax');
	
			?>$("#cpn-<?=$c?> .scrollable .items").parallax({mouseport:$("#cpn-<?=$c?> .scrollable")});<?
			
			break;
			
		case 2: // grouped scrollable + fancybox

?> $("#cpn-<?=$c?> .scrollable").scrollable({
		mousewheel:true
		<?=$s['circular'] ? ', circular:true' : ''?>
	})<?=$s['navigator'] ? '.navigator()' : ''?><?=$s['autoscroll'] ? '.autoscroll(7000)' : ''?>;<?

			break;
	 }


	if ($s['fancybox']) {
?>	$("#cpn-<?=$c?> .items a").fancybox(
	{
		swf: {wmode:"transparent"},
		onComplete: function(e) {
			str = $(this.orig).attr("data-url");			
			found = /\.flv$/i.test(str);
			//console.log(found);
			if(found) {										
						 swfobject.embedSWF("/lib/flowplayer.swf", 
												  "fancybox-content", 
												  <?=0+$im['x']?>, 
												  <?=40 + $im['y']?>, 
												  "8.0.0", 
												  "/lib/expressinstall.swf", {
													f:"<?=$im['fn']?>", e:"<?=$im['type']?>"
												 }, 
												 {wmode: "transparent"}, 
												 {id: "fancybox-content-f"}
												);				
			}
			
		}
	}); <?	
	
	} else if ($s['show_tn']) { 

?> $("#cpn-<?=$c?> .scrollable .items img").click(function() {
		var self = $(this); url = self.attr("data-url"); h = self.attr("data-h"), title = self.attr("title"), descr = self.attr("alt");
		var wrap = $("#cpn-<?=$c?> .image-wrap").fadeTo(100, 0.5);
		var sign = $("#cpn-<?=$c?> .sign");

		var img = new Image();
		img.onload = function() {
			wrap.fadeTo(100, 1);
			wrap.find("img").attr("src", url).attr("height", h);
				sign.find(".title").html(title);
				sign.find(".descr").html(descr);
		};
		img.src = url;
		
		return false;
	}).filter(":first").click(); <?
	
	}
	
?> });</script><? endScript();

	?><section id="cpn-<?=$c?>" class="cpn-gallery2"><?

	if ($s['caption']) { ?><hgroup class="cpn-gallery2-caption"><?=$s['caption']?></hgroup><? }
	
	if (sizeof($d)) {

		/* <div class="navi navi-above"></div> */

		?><a class="prev browse left"></a><div class="scrollable"><div class="items"><?

		if ($s['gtpb']) { $t = 0; ?><div class="block"><? }
	
		foreach($d as $im => $info) {
			
			 if ($s['gtpb'] && (++$t > $s['gtpb'])) { $t = 0; ?><div class="clearer"></div></div><div class="block"><? }

				?><div class="container"><div class="wrapper"><?

				if ($s['nav'] == 2) { ?><a href="<?="$s[path]/$im"?>" rel="gallery"><? }
				
				$fn = $s['show_tn'] ? array('fn' => $info['tn'], 'h' => $info['tnh']) : array('fn' => $info['fn'], 'h' => $info['h']);

			 	?><img src="<?="$s[path]/$fn[fn]"?>" data-url="<?="$s[path]/$im"?>" data-h="<?=$fn['h']?>" title="<?=h($info['title'])?>" alt="<?=h($info['descr'])?>"/><?

				if ($s['nav'] == 2) { ?></a><? }
				
				if ($s['show_title']) { ?><h4 class="title"><?=$info['title']?></h4><? }
				if ($s['show_descr']) { ?><div class="descr"><?=$info['descr']?></div><? }
				
				?></div></div><?
			} 
	
		if ($s['gtpb']) { ?><div class="clearer"></div></div><? }
	
		?></div></div><a class="next browse right"></a><?
		
		?><div class="navi navi-below"></div><?

		?><div class="clearer"></div><?
	
		
		if ($s['show_tn']) {
		
			?><div class="image-wrap"><div class="wrapper"><img src="/img/blank.gif" height="<?=$s['h']?>" /></div></div>
			
				<div class="sign">
					<h2 class="title"></h2>
					<div class="descr"></div>
				</div>
			<?

		}
	}
	
	?></section><?
	
 
	unstack();
}